package standino.velocity.text;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexTool {

	// Returns a version of the input where all contiguous
	// whitespace characters are replaced with a single
	// space. Line terminators are treated like whitespace.
	public static String removeDuplicateWhitespace(CharSequence inputStr) {
		String patternStr = "\\s+";
		String replaceStr = " ";
		Pattern pattern = Pattern.compile(patternStr);
		Matcher matcher = pattern.matcher(inputStr);
		return matcher.replaceAll(replaceStr);
	}

	public static String formateColum2Parameter(String col){
		CharSequence inputStr = col.toLowerCase();
		String patternStr = "_.";

		// Compile regular expression
		Pattern pattern = Pattern.compile(patternStr);

		// Replace all occurrences of pattern in input
		Matcher matcher = pattern.matcher(inputStr);
		String replacementStr = "";

		while (matcher.find()) {
			replacementStr = matcher.group().replace("_", "").toUpperCase();
			inputStr = matcher.replaceFirst(replacementStr); // x b c x b c
			matcher = pattern.matcher(inputStr);
		}

		String output = inputStr.toString();
        
		if(output.length()>0){
			String temp = output.substring(0,1).toUpperCase();
			output = temp + output.substring(1);

		}
		return output;
	}
	public static void main(String[] args) {
		System.out.println(formateColum2Parameter("CREATOR_LAST_NAME"));
	}
}
